package com.ruoyi.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CsOrnamentName;
import com.ruoyi.system.service.ICsOrnamentNameService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 饰品名称Controller
 *
 * @author ruoyi
 * @date 2025-10-04
 */
@Controller
@RequestMapping("/system/name")
public class CsOrnamentNameController extends BaseController {
    private String prefix = "system/name";

    @Autowired
    private ICsOrnamentNameService csOrnamentNameService;


    @GetMapping()
    public String name() {
        return prefix + "/name";
    }

    /**
     * 查询饰品名称列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CsOrnamentName csOrnamentName) {
        startPage();
        List<CsOrnamentName> list = csOrnamentNameService.selectCsOrnamentNameList(csOrnamentName);
        return getDataTable(list);
    }

    /**
     * 导出饰品名称列表
     */
    @Log(title = "饰品名称", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CsOrnamentName csOrnamentName) {
        List<CsOrnamentName> list = csOrnamentNameService.selectCsOrnamentNameList(csOrnamentName);
        ExcelUtil<CsOrnamentName> util = new ExcelUtil<CsOrnamentName>(CsOrnamentName.class);
        return util.exportExcel(list, "饰品名称数据");
    }

    /**
     * 新增饰品名称
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存饰品名称
     */
    @Log(title = "饰品名称", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CsOrnamentName csOrnamentName) {
        return toAjax(csOrnamentNameService.insertCsOrnamentName(csOrnamentName));
    }

    /**
     * 修改饰品名称
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        CsOrnamentName csOrnamentName = csOrnamentNameService.selectCsOrnamentNameById(id);
        mmap.put("csOrnamentName", csOrnamentName);
        return prefix + "/edit";
    }

    /**
     * 修改保存饰品名称
     */
    @Log(title = "饰品名称", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CsOrnamentName csOrnamentName) {
        return toAjax(csOrnamentNameService.updateCsOrnamentNameStatusById(csOrnamentName));
    }

    /**
     * 删除饰品名称
     */
    @Log(title = "饰品名称", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(csOrnamentNameService.deleteCsOrnamentNameByIds(ids));
    }
}
